package com.lance.answer.gui.answer.gk.answer.lms.batch;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.lance.answer.gui.answer.AnswerObject;
import com.lance.answer.gui.answer.DealJsonString;
import com.lance.answer.gui.answer.Util;
import com.lance.answer.gui.answer.gk.answer.lms.batch.dto.LmsWatchDTO;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.DoAnswerTask;
import com.lance.answer.gui.answer.gk.answer.lms.batch.task.DoBigHomeWorkTask;
import com.lance.answer.gui.answer.gk.answer.lms.util.LmsUtil;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 做大作业
 */
public class DoBigHomeWork {


    public static void main(String[] args) throws Exception {


       // Thread.sleep(1000*60*60*7);
        int sync = 8;

        LinkedBlockingDeque<LmsWatchDTO> watchQueue = new LinkedBlockingDeque<>();

        // InputStream inputStream2 = new FileInputStream("libs//lms2022-x.user");
      //  InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//all.user");
        InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//all3.user");
     //   InputStream inputStream2 = new FileInputStream("libs//lmsTeachers//李俊杰2.user");
        List<String> userString = IOUtils.readLines(inputStream2, "utf-8");

        for (String user : userString) {
            String[] strs = user.split(",");
            String userCode = strs[0];
            String pwd = strs[1];
            LmsWatchDTO lmsWatchDTO = new LmsWatchDTO();
            lmsWatchDTO.setUsername(userCode);
            lmsWatchDTO.setPassword(pwd);
//            if (
//                    !"2265001205211".equals(userCode)
//            ) {
//                continue;
//            }

//            Map<Long, String> courseMap = LmsUtil.getUserCourseMap(userCode);
//            Map<Long, String> courseMap = Maps.newHashMap();
//            courseMap.put(10000001761L,"习近平新时代中国特色社会主义思想");
//
//            if(null == courseMap){
//                continue;
//            }
//            lmsWatchDTO.setCourseMap(courseMap);

            Map<Long, String> courseMap = LmsUtil.getUserCourseMap(userCode);
            if (null == courseMap) {
                continue;
            }
            Map<Long, String> newCourseMap = Maps.newHashMap();

            for (Long cId : courseMap.keySet()) {
                String subjectName = courseMap.get(cId);
                if (Strings.isNullOrEmpty(subjectName)) {
                    continue;
                }
                if (subjectName.equals("习近平新时代中国特色社会主义思想")
                          ||subjectName.equals("中国近现代史纲要")
                        || subjectName.equals("习近平总书记教育重要论述研究")
                        || subjectName.equals("毛泽东思想和中国特色社会主义理论体系概论")
                        || subjectName.equals("思想道德与法治")
                   //     || subjectName.equals("形势与政策")
                ) {
                    newCourseMap.put(cId, subjectName);
                }
            }


            lmsWatchDTO.setCourseMap(newCourseMap);


            watchQueue.add(lmsWatchDTO);

        }

        for (int i = 1; i <= sync; i++) {
            Thread answerThread = new DoBigHomeWorkTask("d:\\ynouAutoStudy\\chromedriver.exe", watchQueue);
            //log.info("加载课程ID：{} 名称：{} ", openCourseId,subjectName);
            answerThread.setName("答题线程--" + i);
            answerThread.start();
        }
    }


}
